<template>
    <van-image :src="imgPath" class="van_img" :round="round" :lazy-load="lazyLoad" @click="previewImage(imgPath)" :alt="alt">
      <template v-slot:error>
        <img src="@/assets/images/avatar_default.png" class="default_img" alt="" /> 
      </template>
    </van-image>
</template>
<script>
import config from "@/http/config";
import { ImagePreview } from 'vant';
export default {
  name: "LiImage",
  props: {
    src: {
      type: String,
      default: "",
    },
    lazyLoad: {
      type: Boolean,
      default: true,
    },
    round: {
      type: Boolean,
      default: false,
    },
    isPreview: {
      type: Boolean,
      default: true
    },
    fit:{
      type:String,
      default:'fill'
    },
    alt:{
      type:String,
      default:''
    }
  },
  watch: {
    src: {
      handler: function (n) {
        console.log(n)
        if (n) {
          this.imgPath = this.IMAGEURL + n;
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      IMAGEURL: config.IMAGEURL,
      imgPath: "",
    };
  },
  methods: {

    // 图片预览
    previewImage(path) {
      if (this.isPreview) {
        ImagePreview([path]);
      }
    }

  },
};
</script>
<style lang="less" scoped>
.van_img {
  width: 100%;
  height: 100%;
}
.default_img{
  width: 100%;
  height: 100%;
}
</style>